/**
 * 
 */
package com.ydy.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ydy.annotation.CheckFormRepeat;
import com.ydy.annotation.CtrlParam;
import com.ydy.annotation.StaffToken;
import com.ydy.controller.base.BaseController;
import com.ydy.model.TimeQuantum;
import com.ydy.service.timeQuantum.TimeQuantumService;
import com.ydy.vo.DateVo;
import com.ydy.vo.other.BaseVo;

/**
 * @author xuzhaojie
 *
 *         2019年1月18日 上午9:17:29
 */
@Controller
@RequestMapping(value = "timeQuantum", name = "时间段模块")
public class TimeQuantumController extends BaseController {

	@Autowired
	private TimeQuantumService timeQuantumService;

	@GetMapping(value = "listDate", name = "查找店铺预约日期")
	@ResponseBody
	public ResponseEntity<List<DateVo>> listDate(@CtrlParam("店铺ID") Long shopId) {
		List<DateVo> list = timeQuantumService.listDate(shopId);
		return ResponseEntity.ok(list);
	}

	@GetMapping(value = "list", name = "查找店铺预约某天的时间段")
	@ResponseBody
	public ResponseEntity<DateVo> list(@CtrlParam("店铺ID") Long shopId, @CtrlParam("预约日期") Date date) {
		return ResponseEntity.ok(timeQuantumService.list(shopId, date));
	}

	@StaffToken
	@GetMapping(value = "select", name = "店员查看时间段")
	@ResponseBody
	public ResponseEntity<List<TimeQuantum>> select() {
		List<TimeQuantum> list = timeQuantumService.select(getStaff().getShopId());
		return ResponseEntity.ok(list);
	}

	@StaffToken
	@CheckFormRepeat
	@PostMapping(value = "save", name = "店员保存时间段")
	@ResponseBody
	public ResponseEntity<TimeQuantum> save(TimeQuantum timeQuantum) {
		return ResponseEntity.ok(timeQuantumService.saveOrUpdate(timeQuantum, getStaff()));
	}

	@StaffToken
	@CheckFormRepeat
	@DeleteMapping(value = "delete", name = "店员删除时间段")
	@ResponseBody
	public ResponseEntity<BaseVo> delete(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(timeQuantumService.delete(id, getStaff()));
	}

}